﻿<!DOCTYPE html>

<html lang="en">
<head>
    <!-- The jQuery library is a prerequisite for all jqSuite products -->
    <script type="text/ecmascript" src="../../../js/jquery.min.js"></script> 
    <!-- This is the Javascript file of jqGrid -->   
    <script type="text/ecmascript" src="../../../js/trirand/src/jquery.jqGrid.js"></script>
    <!-- This is the localization file of the grid controlling messages, labels, etc.
    <!-- We support more than 40 localizations -->
    <script type="text/ecmascript" src="../../../js/trirand/i18n/grid.locale-en.js"></script>
    <!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/jquery-ui.css" />
    <!-- The link to the CSS that the grid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/trirand/ui.jqgrid.css" />
    <meta charset="utf-8" />
    <title>jqGrid Loading Data - Get or Set selected grid row</title>
</head>
<body>

    <table id="CitiesMap"></table>
    <div id="CitiesMapPager"></div>

    <br /><br />

    <input type="button" value="Get Selected Row" onclick="getSelectedRow()" />   
    
    <br /><br /> 



    <script type="text/javascript"> 
    
        $(document).ready(function () {
    $('#CitiesMap').jqGrid({
        type: "GET",
        datatype: "json",
        url: "data.json",
        editurl: "/Map/EditCities",
		jsonReader : { id : 0},
        colNames: new Array('ID', 'Name*', 'Region', 'Latitude', 'Longtitude'),
        colModel: new Array(
            {
                name: 'ID', key: false, editable: false, sorttype: 'int', width: 20
            },
            {
                name: 'Name',
                editable: true,
                editrules: {
                    required: true
                }
            },
            {
                name: 'RegionsID',
                editable: true,
                edittype: 'select',
                editoptions: {
                    defaultValue: 18,
                    value: function () {
                        var regions = new Object();
                        $.ajax({
                            url: "/Map/GetRegions",
                            dataType: "json",
                            async: false,
                            success: function (data) {
                                $.each(data.rows, function (index, item) {
                                    regions[item.cell[0]] = item.cell[1];
                                });
                            }
                        });
                        return regions;
                    }
                }
            },
            {
                name: 'Latitude', sorttype: 'float'
            },
            {
                name: 'Longitude', sorttype: 'float'
            }
        ),
        toolbar: [true, "top"],
        sortname: 'ID',
        sortorder: 'asc',
        viewrecords: true,
        rowNum: 26,
        rownumbers: true,
        //width: gridWidth,
        //height: gridHeight,
        pager: '#CitiesMapPager',

        loadonce: false,
        ignoreCase: true
    }).jqGrid('navGrid', '#CitiesMapPager', {
        add: false,
        edit: false,
        del: true,
        search: false,
        refresh: true
    },
      // Delete
	  {},
     // Search
     {}
    ).jqGrid(
        'filterToolbar',
        {
            stringResult: true,
            searchOnEnter: false,
            defaultSearch: 'cn'
        }
    );

		});
        function getSelectedRow() {
            var grid = $("#CitiesMap");
            var rowKey = grid.jqGrid('getGridParam',"selrow");

            if (rowKey)
                alert("Selected row primary key is: " + rowKey);
            else
                alert("No rows are selected");
        }

    </script>

    <!-- This code is related to code tabs -->
    <br />
    <span style="font-size: 12px; font-family: Tahoma">Click on the Tabs below the see the relevant code for the example:</span>
    <br /><br />
    <div id="codetabs" style="width:700px; height: 400px; font-size:65%;"></div>
    <script type="text/ecmascript" src="../../../js/jquery-ui.min.js"></script>
    <script type="text/ecmascript" src="../../../js/prettify/prettify.js"></script>
    <link rel="stylesheet" href="../../../css/prettify.css" />
        <script type="text/ecmascript" src="../../../js/codetabs.js"></script><script type="text/ecmascript" src="../../../js/themeswitchertool.js"></script>
    
    <script type="text/javascript">

        var tabData =
            [
                { name: "HTML", url: "index.html", lang: "lang-html" },
                { name: "Data.JSON", url: "data.json", lang: "lang-json" },
                { name: "Description", url: "description.html", lang: "lang-html" },
            ];

        codeTabs(tabData);

    </script>
    <!-- End of code related to code tabs -->
</body>
</html>